
FROM ubuntu
USER root

ENV CONDA_INSTALL_FILE Miniconda3-py39_4.9.2-Linux-x86_64.sh
ENV CONDA_INSTALL_DIR /opt
ENV PATH /bin:/sbin:$CONDA_INSTALL_DIR/miniconda/bin:/usr/bin
ENV NOTEBOOK_ROOT /notebook
# 设置环境变量，避免tzdata安装交互导致build失败
ENV DEBIAN_FRONTEND noninteractive
# jupyer 密码 
ENV PASSWORD 'abcd1234'
ENV LANG='zh_CN.UTF8'

# 北外的conda源，清华源现在有点慢
ADD .condarc /root/.condarc
# 搞了一堆字体
# ADD winfont /usr/share/fonts/winfont
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list &&\
    apt update -y &&\
    # DEBIAN_FRONTEND=noninteractive apt install tzdata fontconfig tini wget locales -y && \
    apt install tzdata fontconfig tini wget locales -y && \
    #######################################################################
    # 时区和字符集
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone && \
    locale-gen zh_CN.UTF-8 && \
    dpkg-reconfigure tzdata && \
    # 字体，前面没有ADD，这里就不用了
    # cd /usr/share/fonts && fc-cache -f && cd && \
    #######################################################################
    # 下载miniconda的安装包并安装
    wget -q https://mirrors.bfsu.edu.cn/anaconda/miniconda/$CONDA_INSTALL_FILE && \
    mkdir -p $CONDA_INSTALL_DIR && \
    bash ./$CONDA_INSTALL_FILE -b -p $CONDA_INSTALL_DIR/miniconda && \
    rm $CONDA_INSTALL_FILE && \
    mkdir -p /notebook && \
    # 清除缓存，升级conda
    conda clean -i && \
    conda update --all && \
    # 升级base环境中软件
    conda update -n base -c defaults conda -y && \
    # 设置pip源
    pip config set global.index-url https://opentuna.cn/pypi/web/simple && \
    # 安装python包
    conda install -c conda-forge pandas datatable h5py dask \
    xlrd xlwt openpyxl selenium mysql-connector-python pymongo \
    mongoengine sqlalchemy flask bokeh dash jupyter-dash \
    plotly autopep8 yapf jupyterlab jupyter-archive \
    # nodejs用conda装比较好，apt装的包，jupyter总报错
    nodejs -y && \
    # conda没有的包，用pip装
    pip install xeus-python chart_studio psycopg2-binary cufflinks plotly-express \
    echarts-python dash_bootstrap_components && \
    # 安装中文语言包(中文包还未正式发布？离线安装)
    wget -q https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/jupyterhub/jupyterlab_language_pack_zh_CN-0.0.1.dev0-py2.py3-none-any.whl && \
    pip install ./jupyterlab_language_pack_zh_CN-0.0.1.dev0-py2.py3-none-any.whl && \
    rm -f ./jupyterlab_language_pack_zh_CN-0.0.1.dev0-py2.py3-none-any.whl && \
    #######################################################################
    # 创建配置文件
    jupyter-lab --generate-config --allow-root && \
    #######################################################################
    # 以下插件均亲测安装成功
    # draw.io插件
    jupyter-labextension install jupyterlab-drawio && \
    # plotly插件 
    jupyter-labextension install jupyterlab-plotly && \
    jupyter-labextension install jupyterlab-chart-editor && \
    # dash 显示插件
    jupyter-labextension install jupyterlab-dash && \
    # geojson查看
    jupyter labextension install @jupyterlab/geojson-extension && \
    # # excel,csv,ods查看
    jupyter-labextension install jupyterlab-spreadsheet && \
    #######################################################################
    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

VOLUME ["/notebook"]
EXPOSE 8888
ENTRYPOINT [ "/usr/bin/tini", "--" ]
CMD jupyter-lab \
    --allow-root \
    --no-browser \
    --notebook-dir=/notebook \
    --ip=0.0.0.0  \
    --ServerApp.password=`python -c "from jupyter_server.auth import passwd; print(passwd('$PASSWORD'),end='')"`
